#include<bits/stdc++.h>

using namespace std;
int a[101][101], n, m, from, to, dp[101], book[101];
const int INF = 9999;

void bfs(int from) {
    queue<int> Q;
    Q.push(from);
    book[from] = 1;
    while (Q.size()) {
        int head = Q.front();
        for (int i = 1; i <= n; i++) {
            if (book[i] == 0 and a[head][i] == 1) {
                Q.push(i);
                dp[i] = min(dp[head] + 1, dp[i]);
                book[i] = 1;
            }
        }
        Q.pop();
    }
}

int main() {
    while (cin >> n >> m >> from >> to) {
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) {
                a[i][j] = INF;
            }
        fill(book + 1, book + n + 1, false);
        fill(dp + 1, dp + n + 1, INF);
        dp[from] = 0;
        for (int i = 1; i <= m; i++) {
            int x, y;
            cin >> x >> y;
            a[x][y] = 1;
            a[y][x] = 1;
        }
        bfs(from);
        cout << dp[to] << endl;
    }
    return 0;
}